﻿using Framework.Core.BootStrapper.WindowsService;
using Rhino.Mocks;
using Xunit;

namespace Framework.Tests.Core.BootStrapper
{
    class WindowsServiceAdapterForTest : WindowsServiceAdapter<WindowsServiceArgs>
    {
        public WindowsServiceAdapterForTest(IWindowsService<WindowsServiceArgs> windowsService, WindowsServiceArgs args)
            : base(windowsService, args)
        {
        }

        public void OnStartVisible(string[] args)
        {
            OnStart(args);
        }

        public void OnStopVisible()
        {
            OnStop();
        }
    }

    public class WindowsServiceAdapterTest
    {
        private readonly MockRepository mockRepository;
        private readonly WindowsServiceAdapterForTest windowsService;
        private readonly IWindowsService<WindowsServiceArgs> windowsServiceMock;
        private readonly WindowsServiceArgs windowsServiceArgs;

        public WindowsServiceAdapterTest()
        {
            mockRepository = new MockRepository();
            windowsServiceMock = mockRepository.StrictMock<IWindowsService<WindowsServiceArgs>>();
            windowsServiceArgs = new WindowsServiceArgs();
            windowsService = new WindowsServiceAdapterForTest(windowsServiceMock, windowsServiceArgs);
        }

        [Fact]
        public void Should_adapt_start()
        {
            var args = new[] { "/p:pouet" };
            mockRepository.ReplayAll();
            windowsServiceMock.Expect(x => x.Start(windowsServiceArgs));
            windowsService.OnStartVisible(args);
            mockRepository.VerifyAll();
        }

        [Fact]
        public void Should_adapt_stop()
        {
            mockRepository.ReplayAll();
            windowsServiceMock.Expect(x => x.Stop());
            windowsService.OnStopVisible();
            mockRepository.VerifyAll();
        }
    }
}
